<?php

if (!(empty($_POST))) 
{
    $username=isset($_POST["username"]) ? trim($_POST["username"])  : "";
    $password=isset($_POST["password"]) ? trim($_POST["password"])  : "";
    $re=isset($_POST["re"]) ? trim($_POST["re"])  : false;
    
    $oklogin=false;
    require_once'db_conn.php';
    $sql="select * from t_user where username='$username'";
    $rs=$db->query($sql);
    if ($rs)
    {
        $row=$rs->fetch_assoc();
        if ($row['password']==$password)
        {
            $_SESSION["userinfo"]=array(
                "id"=>$row['id'],
                "username"=>$row['username']
            );
            header("Location:main.php");
            die;
        }
    }   
   
        echo "<script language='javascript' type='text/javascript'>";
        echo "alert('登录失败！用户名和密码不正确。');";
        echo "window.location.href='index.php'";
        echo "</script>"; 
        
}

